import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

const routes = [
  {path: '/404', name: '404', component: () => import(/* webpackChunkName: "parent" */ '@/views/common/404'), meta: {title: '404未找到'}},
  {path: '/login', name: 'login', component: () => import(/* webpackChunkName: "parent" */ '@/views/common/Login'), meta: {title: '登录'}},
  {
    path: '/',
    name: 'index',
    component: () => import(/* webpackChunkName: "parent" */ '@/views/common/Index'),
    meta: {title: '首页'},
    redirect: {name: 'dashboard'},
    children: [
        //=-----------------------------------------------------------------------------------------@/views/common/你的新创的页面-------------------------
      {path: 'dashboard', name: 'dashboard', component: () => import(/* webpackChunkName: "child" */ '@/views/common/Dashboard'), meta: {title: '系统首页'}},
      {path: 'organization-list', name: 'organization-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/OrderList'), meta: {title: '机构管理'}},
      {path: 'department-list', name: 'department-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/OrderSetting'), meta: {title: '科室管理'}},
      {path: 'material-list', name: 'material-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/MaterialList'), meta: {title: '耗材管理'}},
      {path: 'nursing-list', name: 'nursing-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/NursingList'), meta: {title: '护理项目管理'}},
      {path: 'role-list', name: 'role-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/RoleList'), meta: {title: '角色管理'}},
      {path: 'user-list', name: 'user-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/UserList'), meta: {title: '员工管理'}},
      {path: 'all-order-list', name: 'all-order-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/AllOrderList'), meta: {title: '全部订单'}},
      {path: 'wait-order-list', name: 'wait-order-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/WaitOrderList'), meta: {title: '待派单'}},
      {path: 'transaction-list', name: 'transaction-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/TransactionList'), meta: {title: '交易记录查询'}},
      {path: 'newspaper-list', name: 'newspaper-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/NewspaperList'), meta: {title: '结算日报表'}},
      {path: 'xm-income-list', name: 'xm-income-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/XmIncomeList'), meta: {title: '项目收入统计表'}},
      {path: 'hs-income-list', name: 'hs-income-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/HsIncomeList'), meta: {title: '护士收入统计表'}},
      {path: 'ks-income-list', name: 'ks-income-list', component: () => import(/* webpackChunkName: "child" */ '@/views/page/KsIncomeList'), meta: {title: '科室收入统计表'}},
    ],
    // 路由导航守卫,用于用户认证
    beforeEnter: (to, from, next) => {
       let loginUser = window.sessionStorage.getItem('loginUser');
       if (loginUser) {
         // 认证成功,允许路由
         next();
       } else {
        // 认证失败,跳转到登录组件
        next({name: 'login'});
      }
    }
  },
  {path: '*', redirect: {name: '404'}}
];

const router =  new VueRouter({
  scrollBehavior: () => ({ x: 0, y: 0 }),
  routes
});

export default router;
